import java.util.List;

//回文链表
class Solution2 {
    class ListNode{
        int val;
        ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode head;
    public boolean isPalindrome(ListNode head) {
        if(head==null){
            return false;
        }
        ListNode slow=head;
        ListNode fast=head;
        while(fast!=null&&fast.next!=null){
            fast=fast.next.next;
            slow=slow.next;
        }
        ListNode cur=slow.next;
        while(cur!=null){
            ListNode curNext=cur.next;
            cur.next=slow;
            slow=cur;
            cur=curNext;
        }
        while(slow!=head){
            if(slow.val==head.val){
                slow=slow.next;
                head=head.next;
            }else{
              return false;
            }
            if(head.next==slow){
                if(head.val==slow.val){
                    return true;
                }
                return false;
            }
        }
        return  true;
    }
}